package fr.znight.chacunsatv.utils;

import java.util.List;

import fr.znight.chacunsatv.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChannelAdapter extends ArrayAdapter {

	protected List<ChaineObject> l;
	protected Context context;
	
	public ChannelAdapter(Context context, int textViewResourceId, List<ChaineObject> objects) {
		super(context, textViewResourceId, objects);
		this.l = objects;
		this.context = context;
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return l.size();
	}
	
	@Override
	public ChaineObject getItem(int position) {
		// TODO Auto-generated method stub
		return l.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		
		if (v == null) {
	        LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        v = vi.inflate(android.R.layout.simple_list_item_1, null);
	    }
        Log.w("DEBUG_CHANNEL", l.get(position).getNumber() + " " + l.get(position).getName());

	    if (l.get(position) != null) {

	        TextView list_title = (TextView) v.findViewById(android.R.id.text1);

	        if (list_title != null) {
	            list_title.setText(l.get(position).getNumber() + " " + l.get(position).getName());
//	            Log.w("DEBUG_CHANNEL", l.get(position).getNumber() + " " + l.get(position).getName());
	        }

	    }

		
		return v;
	}
	
}
